#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1e5 + 10;

int n;
int q[N], num;

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i ++) cin >> q[i], num += q[i];
    for(int i = 1; i <= n; i ++) q[i] = q[i - 1] + q[i];

    int m;
    cin >> m;
    while(m --)
    {
        int l, r;
        cin >> l >> r;
        if(l > r) swap(l, r);
        int dis = q[r - 1] - q[l - 1];
        cout << min(dis, num - dis) << endl;
    }

    return 0;
}